﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
using XinGuanERP.Attributes.system;
using XinGuanERP.Models.Vo.system;
using XinGuanERP.Services.system.IServices;
using XinGuanERP.Utils;

namespace XinGuanERP.Controllers.system
{
    [DynamicApiController]
    public class DictController
    {
        private readonly IDictService _dictService;

        public DictController(IDictService dictService)
        {
            _dictService = dictService;
        }

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetDictWithPage(int page, int pageSize, string? name, string? code)
            => ResultUtil.ok(_dictService.GetDictWithPage(page, pageSize, name, code));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil PostDict(DictVo viewDict)
            => ResultUtil.ok(_dictService.UpdateDict(viewDict));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil DeleteDict(string id)
            => ResultUtil.ok(_dictService.DeleteDict(id));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetDictWithList()
            => ResultUtil.ok(_dictService.GetDictWithList());
    }
}
